<?php

!defined('IN_HDWIKI') && exit('Access Denied');

class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('word');
		$this->view->setlang($this->setting['lang_name'],'back');
	}

 	function dodefault(){
		if(isset($this->post['submit'])){
			$ids = isset($this->post['word_id'])?$this->post['word_id']:'';
			$wordids = $this->post['upword_id'];
			$find = $this->post['find'];
			$replacement = $this->post['replacement'];
			$newfind = string::haddslashes(htmlspecialchars($this->post['newfind']));
			$newreplacement = string::haddslashes(htmlspecialchars($this->post['newreplacement']));
			$words = NULL;
			if(is_array($wordids)){
				foreach($wordids as $id => $wordid){
					$words[] = array('id'=>$wordid,'find'=>$find[$id],'replacement'=>$replacement[$id]);
				}
			}
			if($ids){$_ENV['word']->del_words($ids);}
			if($newfind){$_ENV['word']->add_word($newfind,$newreplacement,$this->user['username']);}
			if($words){$_ENV['word']->edit_words($words,$this->user['username']);}
			$this->cache->removecache('word');
			$this->message($this->view->lang['usermanageOptSuccess'],'index.php?admin_word');
		}else{
			$page = max(1, intval($this->get[2]));
			$num = isset($this->setting['list_prepage'])?$this->setting['list_prepage']:20;
			$start_limit = ($page - 1) * $num;
		
			$allnum = $_ENV['word']->get_word_num();
			$words = $_ENV['word']->get_word_list($start_limit,$num);
			$departstr=$this->multi($allnum, $num, $page,'admin_word-default');
			$this->view->assign('departstr',$departstr);
			$this->view->assign('words',$words);
			$this->view->display('admin_word');
		}
	}
}

?>